import { RJSFSchema } from '@rjsf/utils';
import { getNormalsOrIds, Picktip, SetPick } from './tools';
const setSchema = (item): RJSFSchema => ({
  type: 'object',
  properties: {
    ...item,
    isEmSo: {
      type: 'boolean',
      title: '是否嵌入源对象',
      default: true,
    },
    isEmtarg: {
      type: 'boolean',
      title: '是否嵌入目标对象',
      default: false,
    },
  },
});

const schemaParam = (hasPkMod: boolean = false) => ({
  relyOn1: SetPick(['PickCurve', 'PickLine', 'PickSurface']),
  relyOn2: SetPick(
    !hasPkMod ? ['PickCurve', 'PickLine', 'PickSurface'] : ['PickModel'],
  ),
});
// formData 参数
export const intersect = {
  line: setSchema(schemaParam()),
  model: setSchema(schemaParam(true)),
};

const lineTip = (hasPkMod: boolean = false) => ({
  relyOn1: Picktip(true, '源边/直线/面'),
  relyOn2: Picktip(false, !hasPkMod ? '目标边/直线/面' : '目标体'),
});

// formData input 框提示
export const extraUiSchema = {
  line: lineTip(),
  model: lineTip(true),
};

// 参数整理  传入后端的参数 --- 线
export const lineParam = (formData) => {
  const ids = getNormalsOrIds([formData.relyOn1, formData.relyOn2], 'id').map(
    (it) => it.id,
  );
  if (ids.length === 2) {
    const param = {
      target: [ids?.[0]],
      source: [ids?.[1]],
      isEmbeded: [formData.isEmSo, formData.isEmtarg],
    };
    return param;
  }
  return null;
};
